<template>
  <div class="layout-aside-container">
    <!-- 左侧边栏列表 -->
    <ul class="user-select-none menu">
      <li class="menu-item">
        <router-link to="/index/employees">职工管理</router-link>
      </li>
      <li class="menu-item">
        <router-link to="/index/roleapply">权限申请</router-link>
      </li>
      <li class="menu-item">
        <router-link to="/index/notice">实时通知</router-link>
      </li>
      <li class="menu-item">
        <router-link to="/index/personal">个人中心</router-link>
      </li>
      <el-badge :value="badgeValue" class="item menu-item" type="primary" :hidden="!isShowBadge" style="display: block">
        <router-link to="/index/audit">申请审核</router-link>
      </el-badge>
    </ul>
  </div>
</template>

<script>
import bus from '@/components/bus'
export default {
  name: 'MyAside',
  data() {
    return {
      roleApplyList: [],
    }
  },
  created() {
    if (this.$store.state.userInfo.role === 1) {
      this.getRoleApplyList()
    }
    bus.$on('updateRoleList', () => this.getRoleApplyList())
  },
  methods: {
    async getRoleApplyList() {
      const { data: res } = await this.$http.get('/api/role/roleapplylist')
      if (res.status === 1) return this.$message(res.message)
      this.roleApplyList = res
    },
  },
  computed: {
    isShowBadge() {
      return this.roleApplyList.some((item) => item.apply_status === 0)
    },
    badgeValue() {
      return this.roleApplyList.filter((item) => item.apply_status === 0).length
    },
  },
}
</script>

<style lang="less" scoped>
.layout-aside-container {
  width: 250px;
  height: 100%;
  border-right: 1px solid #eaeaea;
}

.menu {
  list-style-type: none;
  padding: 0;
  .menu-item {
    line-height: 50px;
    font-weight: bold;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    &:hover {
      background-color: #efefef;
      cursor: pointer;
    }
    a {
      display: block;
      color: black;
      padding-left: 30px;
      &:hover {
        text-decoration: none;
      }
    }
  }
}

// 设置路由高亮效果
.router-link-active {
  background-color: #efefef;
  box-sizing: border-box;
  position: relative;
  // 伪元素实现路由高亮效果
  &::before {
    content: ' ';
    display: block;
    width: 4px;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    background-color: #42b983;
  }
}
</style>
